<template>
  <div class="contract-panel-container">
    <el-table :data="contractData" style="width: 100%">
      <el-table-column prop="employeeContractTypeName" label="类型" width="180" align="center"></el-table-column>
      <el-table-column prop="employeeContractCode" label="编号"  align="center"></el-table-column>
      <el-table-column prop="employeeContractTerm" label="期限" width="180" align="center"></el-table-column>
      <el-table-column prop="employeeContractStartTime" label="开始日期" width="180" align="center"></el-table-column>
      <el-table-column prop="employeeContractEndTime" label="结束日期" width="180" align="center"></el-table-column>
      <el-table-column prop="isEnable" label="状态" width="180" align="center"></el-table-column>
      <el-table-column prop="employeeContractStamp" label="盖章状态" width="120" align="center"></el-table-column>
      <el-table-column prop="employeeContractReceive" label="领取状态" width="120" align="center"></el-table-column>
      <el-table-column label="附件" align="center" width="120">
        <template slot-scope="scope" >
          <el-button
            size="mini"
            type="text"
            @click="downloadAllFiles(scope.row.employeeContractId,null)"
            v-hasPermi="['system:menu:edit']"
          >
            下载附件
          </el-button>
        </template>
      </el-table-column>
      <el-table-column prop="organizationCode" label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="edit(scope.row)"
            v-hasPermi="['system:menu:edit']"
          >
            修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="del(scope.row)"
            v-hasPermi="['system:menu:remove']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="queryParams.current"
      layout="total, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <edit v-if="editData.open" :prop="editData" @close="closeEdit"></edit>
    <downloadfile v-if="downloadData.open" :prop="downloadData"></downloadfile>
  </div>
</template>

<script>
import {getPageList} from '@/api/employee/employeeContract/employeeContract.js'
import edit from '@/views/employee/contract/edit.vue'
import downloadfile from '@/views/components/DownloadAllFile/downloadFile.vue'
export default {
  name: "Contract",
  dicts: [],
  components: { edit ,downloadfile},
  props:{
    prop:{
      type:Object,
      default:function(){
        return {
          employeeId:null,
          employeeCode:null,
        }
      }
    },

  },
  data() {
    return {
      queryParams:{
        size:10,
        current:1,
        employeeCode:this.prop.employeeCode
      },
      total:0,
      contractData:[],
      editOpen:false,
      editData:{
        open:false,
        title:'新增合同/协议',
        id:null,
      },
      downloadData:{
        open:false,
        title:'下载附件',
        id:null,
        typeId:null
      },
    };
  },
  methods: {
    getPageList(){
      getPageList(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.contractData = res.data.page.records;
          this.contractData.forEach(item =>{
            item.isEnable = item.isEnable ==='0'?'已到期':'执行中'
            item.employeeContractStamp = item.employeeContractStamp ==='0'?'未盖章':'已盖章'
            item.employeeContractReceive = item.employeeContractReceive ==='0'?'未领取':'已领取'
            item.employeeContractTerm = item.employeeContractTerm+item.employeeContractTermUnitName
          })
          this.total = res.data.page.total;
        }
      }).catch(err =>{
        console.log('加载员工合同列表数据失败，原因：',err)
      })
    },
    // 切换页码
    handleSizeChange(val) {
      this.queryParams.size = val;
      this.getPageList();
    },
    // 翻页
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getPageList();
    },
    edit(row){
      this.editData.open = true
      this.editData.id = row.employeeContractId
      this.editData.title = '修改合同/协议'
    },
    /** 删除按钮操作 */
    del(row) {
      this.$confirm('是否删除合同及其相关信息？','确认信息',{
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      }).then(()=>{
        del({employeeContractId:row.employeeContractId}).then(res =>{
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.getPageList()
        })
      }).catch(action => {

      });
    },
    closeEdit(){
      this.editData.open = false
      this.editData.id = null
      this.editData.title = '新增合同/协议'
      this.getPageList()
    },
    downloadAllFiles(id,typeId){
      this.downloadData = {
        open:true,
        title:'下载附件',
        id:id,
        typeId:typeId
      }
    },
    closeDetail(){
      this.detailOpen = false
      this.detailData.id = null
    }
  },
  mounted() {
    this.getPageList()
  },
  updated() {

  }

};
</script>
<style scoped>
.contract-panel-container{
  height: 58vh;
  overflow-y: auto;
}
</style>
